const path = require('path')

function resolveAlias (dir) {
  return path.resolve(__dirname, 'src', dir)
}

function mergeAlias (config) {
  let alias = config.resolve.alias

  const aliasDirs = [
    'views',
    'store',
    'router',
    'components',
    'assets',
    'api',
  ]

  aliasDirs.forEach(dir => {
    alias.set(dir, resolveAlias(dir))
  })
}

module.exports = {
  devServer: {
    compress: true,
    proxy: {
      '/qq': {
        target: 'https://c.y.qq.com',
        changeOrigin: false,
        pathRewrite: {
          '^/qq': ''
        }
      }
    }
  },
  chainWebpack: config => {
    mergeAlias(config)
  }
}
